package com.kerbores.blog.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Record;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.ContinueLoop;
import org.nutz.lang.Each;
import org.nutz.lang.ExitLoop;
import org.nutz.lang.Lang;
import org.nutz.lang.LoopException;

import com.kerbores.blog.bean.Tag;
import com.kerbores.blog.dao.ITagDao;
import com.kerbores.utils.db.SqlActuator;
import com.kerbores.utils.db.dao.impl.BaseDao;

/**
 * @author Ixion <br>
 *         create at 2014年10月26日
 */
@IocBean(name = "tagDao")
public class TagDaoImpl extends BaseDao<Tag> implements ITagDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.kerbores.utils.db.dao.impl.BaseDao#initClass()
	 */
	@Override
	public Class<Tag> initClass() {
		return Tag.class;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.kerbores.blog.dao.ITagDao#findByIds(java.lang.String)
	 */
	@Override
	public List<Tag> findByIds(String tagInfo) {
		String select = "select id , tag_name as name from b_tag where id in (@ids)";
		Sql sql = Sqls.create(select);
		sql.params().set("ids", tagInfo);
		List<Record> records = SqlActuator.runReport(sql, dao);
		final List<Tag> tags = new ArrayList<Tag>();
		Lang.each(records, new Each<Record>() {
			@Override
			public void invoke(int index, Record record, int length) throws ExitLoop, ContinueLoop, LoopException {
				tags.add(record.toPojo(Tag.class));
			}
		});
		return tags;
	}
}
